#!/bin/bash

set -e  # 遇到错误时立即退出

VOLUME_PERCENT=130  # 设定默认音量百分比

echo "[scripts]: Searching for device (alsa_output.usb-Jieli_Technology_UACDemoV1.0)..."

# 查找设备名
PA_DEFAULT_SINK_NAME=$(pactl list short sinks | grep "alsa_output.usb-Jieli_Technology_UACDemoV1.0" | awk '{print $2}')

# 判断是否找到设备
if [ -z "$PA_DEFAULT_SINK_NAME" ]; then
    echo -e "\e[31m[scripts]: Error: No matching audio output device found!\e[0m"
    exit 1
fi

echo "[scripts]: Found device: $PA_DEFAULT_SINK_NAME"

# 设置默认音频输出设备
echo "[scripts]: Setting $PA_DEFAULT_SINK_NAME as the default output device..."
pactl set-default-sink "$PA_DEFAULT_SINK_NAME"

# 设置默认音量
echo "[scripts]: Setting volume of $PA_DEFAULT_SINK_NAME to ${VOLUME_PERCENT}%..."
pactl set-sink-volume "$PA_DEFAULT_SINK_NAME" "${VOLUME_PERCENT}%"

echo -e "[scripts]: Default output device setup completed successfully!\n"
